package org.stone.project.tx.prop;

import cn.hutool.core.util.ObjectUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Data
@Configuration
@ConfigurationProperties("tx-config")
public class TxProp {
    /**
     * 用户最大连接数
     */
    private int userMaxLinkNum = 3;

    /**
     * 0 无操作
     * 1 返回发送成功的用户
     * 2 返回未发送的用户
     * 3 返回成功与未成功的用户
     */
    private int sendResultType = 0;

    /**
     * 本地ip
     */
    private String localIp;

    /**
     * 应用端口
     */
    private Integer port = 9000;

    @PostConstruct
    public void checkParam(){
        if (ObjectUtil.isEmpty(localIp)){
            throw new IllegalArgumentException("ip不能为空");
        }
        if (ObjectUtil.isNull(port)){
            throw new IllegalArgumentException("端口不能为空");
        }
    }
}
